
from typing import Optional
from sqlalchemy.orm import Session
from mooc.crud.crud_base import CRUDBase
from mooc.models.users import (
Users,
UsersBind,
UsersCreateGroup,
UsersGroup,
UsersInvitation,
UsersLastUse,
UsersLoginLogs,
UsersOperateHistory,
UsersOperateStar,
UsersPermission,
UsersProfile,
UsersExtraGroup,
UsersExtraLimit,
UsersExtraModules,
UsersExtraTemplates,
UsersFailedLogin,
UsersFounderGroup,
UsersFounderOwnCreateGroups,
UsersFounderOwnUniGroups,
UsersFounderOwnUsers,
UsersFounderOwnUsersGroups
)
from mooc.schemas.users import (
UsersCreate, UsersUpdate,
UsersBindCreate, UsersBindUpdate,
UsersCreateGroupCreate, UsersCreateGroupUpdate,
UsersGroupCreate, UsersGroupUpdate,
UsersInvitationCreate, UsersInvitationUpdate,
UsersLastUseCreate, UsersLastUseUpdate,
UsersLoginLogsCreate, UsersLoginLogsUpdate,
UsersOperateHistoryCreate, UsersOperateHistoryUpdate,
UsersOperateStarCreate, UsersOperateStarUpdate,
UsersPermissionCreate, UsersPermissionUpdate,
UsersProfileCreate, UsersProfileUpdate,
UsersExtraGroupCreate, UsersExtraGroupUpdate,
UsersExtraLimitCreate, UsersExtraLimitUpdate,
UsersExtraModulesCreate, UsersExtraModulesUpdate,
UsersExtraTemplatesCreate, UsersExtraTemplatesUpdate,
UsersFailedLoginCreate, UsersFailedLoginUpdate,
UsersFounderGroupCreate, UsersFounderGroupUpdate,
UsersFounderOwnCreateGroupsCreate, UsersFounderOwnCreateGroupsUpdate,
UsersFounderOwnUniGroupsCreate, UsersFounderOwnUniGroupsUpdate,
UsersFounderOwnUsersCreate, UsersFounderOwnUsersUpdate,
UsersFounderOwnUsersGroupsCreate, UsersFounderOwnUsersGroupsUpdate
)


class CRUDUsers(CRUDBase[Users, UsersCreate, UsersUpdate]):
    def get_by_uid(self, db: Session, *, uid: int) -> Optional[Users]:
        return self.get_by_field(db, "uid", uid)

    def get_by_username(self, db: Session, *, username: str) -> Optional[Users]:
        return self.get_by_field(db, "username", username)


class CRUDUsersBind(CRUDBase[UsersBind, UsersBindCreate, UsersBindUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersBind]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersBind]:
        return self.get_by_field(db, "uid", uid)


class CRUDUsersCreateGroup(CRUDBase[UsersCreateGroup, UsersCreateGroupCreate, UsersCreateGroupUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersCreateGroup]:
        return self.get_by_field(db, "id", id)

    def get_by_group_name(self, db: Session, *, group_name: str) -> Optional[UsersCreateGroup]:
        return self.get_by_field(db, "group_name", group_name)


class CRUDUsersExtraGroup(CRUDBase[UsersExtraGroup, UsersExtraGroupCreate, UsersExtraGroupUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersExtraGroup]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersExtraGroup]:
        return self.get_by_field(db, "uid", uid)



class CRUDUsersExtraLimit(CRUDBase[UsersExtraLimit, UsersExtraLimitCreate, UsersExtraLimitUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersExtraLimit]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersExtraLimit]:
        return self.get_by_field(db, "uid", uid)


class CRUDUsersExtraModules(CRUDBase[UsersExtraModules, UsersExtraModulesCreate, UsersExtraModulesUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersExtraModules]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersExtraModules]:
        return self.get_by_field(db, "uid", uid)


class CRUDUsersExtraTemplates(CRUDBase[UsersExtraTemplates, UsersExtraTemplatesCreate, UsersExtraTemplatesUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersExtraTemplates]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersExtraTemplates]:
        return self.get_by_field(db, "uid", uid)


class CRUDUsersFailedLogin(CRUDBase[UsersFailedLogin, UsersFailedLoginCreate, UsersFailedLoginUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersFailedLogin]:
        return self.get_by_field(db, "id", id)

    def get_by_username(self, db: Session, *, username: str) -> Optional[UsersFailedLogin]:
        return self.get_by_field(db, "username", username)


class CRUDUsersFounderGroup(CRUDBase[UsersFounderGroup, UsersFounderGroupCreate, UsersFounderGroupUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersFounderGroup]:
        return self.get_by_field(db, "id", id)

    def get_by_name(self, db: Session, *, name: str) -> Optional[UsersFounderGroup]:
        return self.get_by_field(db, "name", name)


class CRUDUsersFounderOwnCreateGroups(CRUDBase[UsersFounderOwnCreateGroups, UsersFounderOwnCreateGroupsCreate, UsersFounderOwnCreateGroupsUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersFounderOwnCreateGroups]:
        return self.get_by_field(db, "id", id)

    def get_by_founder_uid(self, db: Session, *, founder_uid: int) -> Optional[UsersFounderOwnCreateGroups]:
        return self.get_by_field(db, "founder_uid", founder_uid)



### CRUD操作类 for UsersFounderOwnUniGroups表
class CRUDUsersFounderOwnUniGroups(CRUDBase[UsersFounderOwnUniGroups, UsersFounderOwnUniGroupsCreate, UsersFounderOwnUniGroupsUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersFounderOwnUniGroups]:
        return self.get_by_field(db, "id", id)

    def get_by_founder_uid(self, db: Session, *, founder_uid: int) -> Optional[UsersFounderOwnUniGroups]:
        return self.get_by_field(db, "founder_uid", founder_uid)


### CRUD操作类 for UsersFounderOwnUsers表
class CRUDUsersFounderOwnUsers(CRUDBase[UsersFounderOwnUsers, UsersFounderOwnUsersCreate, UsersFounderOwnUsersUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersFounderOwnUsers]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersFounderOwnUsers]:
        return self.get_by_field(db, "uid", uid)


### CRUD操作类 for UsersFounderOwnUsersGroups表
class CRUDUsersFounderOwnUsersGroups(CRUDBase[UsersFounderOwnUsersGroups, UsersFounderOwnUsersGroupsCreate, UsersFounderOwnUsersGroupsUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersFounderOwnUsersGroups]:
        return self.get_by_field(db, "id", id)

    def get_by_founder_uid(self, db: Session, *, founder_uid: int) -> Optional[UsersFounderOwnUsersGroups]:
        return self.get_by_field(db, "founder_uid", founder_uid)


### CRUD操作类 for UsersGroup表
class CRUDUsersGroup(CRUDBase[UsersGroup, UsersGroupCreate, UsersGroupUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersGroup]:
        return self.get_by_field(db, "id", id)

    def get_by_name(self, db: Session, *, name: str) -> Optional[UsersGroup]:
        return self.get_by_field(db, "name", name)


### CRUD操作类 for UsersInvitation表
class CRUDUsersInvitation(CRUDBase[UsersInvitation, UsersInvitationCreate, UsersInvitationUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersInvitation]:
        return self.get_by_field(db, "id", id)

    def get_by_code(self, db: Session, *, code: str) -> Optional[UsersInvitation]:
        return self.get_by_field(db, "code", code)


### CRUD操作类 for UsersLastuse表
class CRUDUsersLastuse(CRUDBase[UsersLastUse, UsersLastUseCreate, UsersLastUseUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersLastUse]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersLastUse]:
        return self.get_by_field(db, "uid", uid)


### CRUD操作类 for UsersLoginLogs表
class CRUDUsersLoginLogs(CRUDBase[UsersLoginLogs, UsersLoginLogsCreate, UsersLoginLogsUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersLoginLogs]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersLoginLogs]:
        return self.get_by_field(db, "uid", uid)


### CRUD操作类 for UsersOperateHistory表
class CRUDUsersOperateHistory(CRUDBase[UsersOperateHistory, UsersOperateHistoryCreate, UsersOperateHistoryUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersOperateHistory]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersOperateHistory]:
        return self.get_by_field(db, "uid", uid)



### CRUD操作类 for UsersOperateStar表
class CRUDUsersOperateStar(CRUDBase[UsersOperateStar, UsersOperateStarCreate, UsersOperateStarUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersOperateStar]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersOperateStar]:
        return self.get_by_field(db, "uid", uid)


### CRUD操作类 for UsersPermission表
class CRUDUsersPermission(CRUDBase[UsersPermission, UsersPermissionCreate, UsersPermissionUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersPermission]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersPermission]:
        return self.get_by_field(db, "uid", uid)


### CRUD操作类 for UsersProfile表
class CRUDUsersProfile(CRUDBase[UsersProfile, UsersProfileCreate, UsersProfileUpdate]):
    def get_by_id(self, db: Session, *, id: int) -> Optional[UsersProfile]:
        return self.get_by_field(db, "id", id)

    def get_by_uid(self, db: Session, *, uid: int) -> Optional[UsersProfile]:
        return self.get_by_field(db, "uid", uid)


# 创建实例
users_operate_star_crud = CRUDUsersOperateStar(UsersOperateStar)
users_permission_crud = CRUDUsersPermission(UsersPermission)
users_profile_crud = CRUDUsersProfile(UsersProfile)
# 创建实例
users_lastuse_crud = CRUDUsersLastuse(UsersLastUse)
users_login_logs_crud = CRUDUsersLoginLogs(UsersLoginLogs)
users_operate_history_crud = CRUDUsersOperateHistory(UsersOperateHistory)

# 创建实例
users_founder_own_uni_groups_crud = CRUDUsersFounderOwnUniGroups(UsersFounderOwnUniGroups)
users_founder_own_users_crud = CRUDUsersFounderOwnUsers(UsersFounderOwnUsers)
users_founder_own_users_groups_crud = CRUDUsersFounderOwnUsersGroups(UsersFounderOwnUsersGroups)
users_group_crud = CRUDUsersGroup(UsersGroup)
users_invitation_crud = CRUDUsersInvitation(UsersInvitation)
# 创建实例
users_extra_limit_crud = CRUDUsersExtraLimit(UsersExtraLimit)
users_extra_modules_crud = CRUDUsersExtraModules(UsersExtraModules)
users_extra_templates_crud = CRUDUsersExtraTemplates(UsersExtraTemplates)
users_failed_login_crud = CRUDUsersFailedLogin(UsersFailedLogin)
users_founder_group_crud = CRUDUsersFounderGroup(UsersFounderGroup)
users_founder_own_create_groups_crud = CRUDUsersFounderOwnCreateGroups(UsersFounderOwnCreateGroups)
# 创建实例
users_crud = CRUDUsers(Users)
users_bind_crud = CRUDUsersBind(UsersBind)
users_create_group_crud = CRUDUsersCreateGroup(UsersCreateGroup)
users_extra_group_crud = CRUDUsersExtraGroup(UsersExtraGroup)